package com.vast.ui.component.util;


import java.text.SimpleDateFormat;
import java.util.Date;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;

public class SaveDialog {
	
	private Composite parent;
	private Display   display;
	private FileDialog saveDialog;
	private String     filterPath;
	private String[]   filterNames;
	private String[]   fileNames;
	private String[]   filterExtensions;
	
	public SaveDialog(Composite parent, String filterPath, String[] filterNames, String[] filterExtensions) {
		this.parent  = parent;
		this.display = parent.getDisplay();
		
		this.filterPath       = filterPath;
		this.filterNames      = filterNames;
		this.filterExtensions = filterExtensions;
		
		this.saveDialog = new FileDialog (this.parent.getShell(), SWT.SAVE);
		this.saveDialog.setFilterNames (this.filterNames);
		this.saveDialog.setFilterExtensions (this.filterExtensions);
		this.saveDialog.setFilterPath (this.filterPath);
		this.saveDialog.setFileName ("myfile");
	}
	
	public String openSaveDialog(String fileNameBody, boolean qualifierEnabled) {
		if(qualifierEnabled) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			Date date1 = new Date();
			String qualifier = sdf.format(date1);
			this.saveDialog.setFileName(fileNameBody + "_" + qualifier);			
		} else {
			this.saveDialog.setFileName(fileNameBody);
		}
		this.filterPath = saveDialog.open();
		return this.filterPath;
	}
	
	
	
	
	
	

	
}
